﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Entity;

namespace DAL.Persistencia
{
    public class InvoiceDAL
    {

        private NewTierraEntities Con;

        public InvoiceDAL()
        {
            Con = new NewTierraEntities();
        }

        public void Salvar(Invoice i)
        {
            try
            {
                Con.AddToInvoice(i);
                Con.SaveChanges();
            }
            catch 
            {                
                throw;
            }
        }

        public List<Invoice> listaInvoicesPorQuotationGrupo(int quotationGrupo)
        {
            return Con.Invoice.Where(d => d.Quotation_Grupo_Id == quotationGrupo).ToList();
        }

        public Invoice ultimoInvoice(int quotationGroup)
        {
            return Con.Invoice.Where(d => d.Quotation_Grupo_Id == quotationGroup).OrderByDescending(c => c.DataEmissao).FirstOrDefault();
        }

    }
}
